#!/bin/bash
client=$1
site=$2
site=$3

echo 'name "saas-aio_'$node'"
description "Client Lumis SAAS AIO role."
run_list(
  "role[saas-aio]"
)
override_attributes(
  "lumisportal" => {
    "vhosts_servername" => "'$site'",
    "frameworkurl" => "http://'$site'"
  }
)' > /home/ec2-user/chef-repo/roles/saas-aio_$node.rb

echo '{
  "id": "'$user'",
  "comment": "Usuario Cliente",
  "groups": [ "saas-aio-'$node'" ],
  "ssh_keys": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDnYicpnzg0bDzYbKyGooRKpqbCSfGIkxrhKnMtdGGfOruMSkXZXJPYvIA0rGtTTZSe2/fOFwjo1IQpkrg6++iLzoXN1edy0yCbeX48eK6UmzpyesAxqx7VcnjDozFgw1AYxrBt06TiJ15JeSs99AattCohoikJH6a+gXM0MH+gTQ== Alexandre Ribeiro de Souza",
  "shell": "/bin/bash",
  "openid": "",
  "nagios": {
    "pager": "",
    "email": ""
  }
}' > /home/ec2-user/chef-repo/data_bags/users/$user.json

pushd /home/ec2-user/chef-repo

knife role from file roles/saas-aio_$node.rb
knife data bag from file users data_bags/users/$user.json
knife ec2 server create -i /home/ec2-user/.ssh/knife-keypair.pem -x ec2-user -r "role[saas-aio_$node], " -G saas-aio -E saas-aio -N saas-aio-$node

popd

